package com.melesta.engine;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.EGLConfigChooser;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.inputmethod.InputMethodManager;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;

public class EngineGLSurfaceView extends GLSurfaceView
{
  private static final int HANDLER_CLOSE_IME_KEYBOARD = 3;
  private static final int HANDLER_OPEN_IME_KEYBOARD = 2;
  private static final String TAG = EngineGLSurfaceView.class.getSimpleName();
  private static EngineGLSurfaceView mCocos2dxGLSurfaceView;
  private static EngineTextInputWraper sCocos2dxTextInputWraper;
  private static Handler sHandler;
  private EngineEditText mCocos2dxEditText;
  private Renderer mCocos2dxRenderer;

  public EngineGLSurfaceView(Context paramContext)
  {
    super(paramContext);
    initView();
  }

  public EngineGLSurfaceView(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    initView();
  }

  public static void closeIMEKeyboard()
  {
    Message localMessage = new Message();
    localMessage.what = 3;
    sHandler.sendMessage(localMessage);
  }

  private static void dumpMotionEvent(MotionEvent paramMotionEvent)
  {
    String[] arrayOfString = { "DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE", "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?" };
    StringBuilder localStringBuilder = new StringBuilder();
    int i = paramMotionEvent.getAction();
    int j = i & 0xFF;
    localStringBuilder.append("event ACTION_").append(arrayOfString[j]);
    if ((j == 5) || (j == 6))
    {
      localStringBuilder.append("(pid ").append(i >> 8);
      localStringBuilder.append(")");
    }
    localStringBuilder.append("[");
    for (int k = 0; k < paramMotionEvent.getPointerCount(); k++)
    {
      localStringBuilder.append("#").append(k);
      localStringBuilder.append("(pid ").append(paramMotionEvent.getPointerId(k));
      localStringBuilder.append(")=").append((int)paramMotionEvent.getX(k));
      localStringBuilder.append(",").append((int)paramMotionEvent.getY(k));
      if (k + 1 < paramMotionEvent.getPointerCount())
        localStringBuilder.append(";");
    }
    localStringBuilder.append("]");
    Log.d(TAG, localStringBuilder.toString());
  }

  private String getContentText()
  {
    return this.mCocos2dxRenderer.getContentText();
  }

  public static void openIMEKeyboard()
  {
    Message localMessage = new Message();
    localMessage.what = 2;
    localMessage.obj = mCocos2dxGLSurfaceView.getContentText();
    sHandler.sendMessage(localMessage);
  }

  public static void queueAccelerometer(float paramFloat1, float paramFloat2, float paramFloat3, long paramLong)
  {
  }

  public void deleteBackward()
  {
    queueEvent(new Runnable()
    {
      public void run()
      {
        EngineGLSurfaceView.this.mCocos2dxRenderer.handleDeleteBackward();
      }
    });
  }

  public EngineEditText getCocos2dxEditText()
  {
    return this.mCocos2dxEditText;
  }

  protected void initView()
  {
    setEGLContextClientVersion(1);
    setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser()
    {
      public EGLConfig chooseConfig(EGL10 paramAnonymousEGL10, EGLDisplay paramAnonymousEGLDisplay)
      {
        EGLConfig[] arrayOfEGLConfig = new EGLConfig[1];
        int[] arrayOfInt1 = new int[1];
        int[] arrayOfInt2 = { 12325, 16, 12326, 8, 12344 };
        if (!paramAnonymousEGL10.eglInitialize(paramAnonymousEGLDisplay, new int[] { 1, 0 }));
        while ((!paramAnonymousEGL10.eglChooseConfig(paramAnonymousEGLDisplay, arrayOfInt2, arrayOfEGLConfig, 1, arrayOfInt1)) && (!paramAnonymousEGL10.eglChooseConfig(paramAnonymousEGLDisplay, null, arrayOfEGLConfig, 1, arrayOfInt1)))
          return null;
        return arrayOfEGLConfig[0];
      }
    });
    setFocusableInTouchMode(true);
    mCocos2dxGLSurfaceView = this;
    sCocos2dxTextInputWraper = new EngineTextInputWraper(this);
    sHandler = new Handler()
    {
      public void handleMessage(Message paramAnonymousMessage)
      {
        EngineEditText localEngineEditText = EngineGLSurfaceView.this.mCocos2dxEditText;
        EngineGLSurfaceView localEngineGLSurfaceView = EngineGLSurfaceView.mCocos2dxGLSurfaceView;
        switch (paramAnonymousMessage.what)
        {
        default:
        case 2:
        case 3:
        }
        do
        {
          do
            return;
          while ((localEngineEditText == null) || (!localEngineEditText.requestFocus()));
          localEngineEditText.removeTextChangedListener(EngineGLSurfaceView.sCocos2dxTextInputWraper);
          localEngineEditText.setText("");
          String str = (String)paramAnonymousMessage.obj;
          localEngineEditText.append(str);
          EngineGLSurfaceView.sCocos2dxTextInputWraper.setOriginText(str);
          localEngineEditText.addTextChangedListener(EngineGLSurfaceView.sCocos2dxTextInputWraper);
          ((InputMethodManager)localEngineGLSurfaceView.getContext().getSystemService("input_method")).showSoftInput(localEngineEditText, 0);
          Log.d("GLSurfaceView", "showSoftInput");
          return;
        }
        while (localEngineEditText == null);
        localEngineEditText.removeTextChangedListener(EngineGLSurfaceView.sCocos2dxTextInputWraper);
        ((InputMethodManager)localEngineGLSurfaceView.getContext().getSystemService("input_method")).hideSoftInputFromWindow(localEngineEditText.getWindowToken(), 0);
        EngineGLSurfaceView.this.requestFocus();
        Log.d("GLSurfaceView", "HideSoftInput");
      }
    };
  }

  public void insertText(final String paramString)
  {
    queueEvent(new Runnable()
    {
      public void run()
      {
        EngineGLSurfaceView.this.mCocos2dxRenderer.handleInsertText(paramString);
      }
    });
  }

  public boolean onKeyDown(final int paramInt, final KeyEvent paramKeyEvent)
  {
    boolean bool = true;
    switch (paramInt)
    {
    default:
      if (isEnabled())
        bool = super.onKeyDown(paramInt, paramKeyEvent);
      break;
    case 4:
    case 82:
      do
        return bool;
      while (!isEnabled());
      queueEvent(new Runnable()
      {
        public void run()
        {
          EngineGLSurfaceView.this.mCocos2dxRenderer.handleKeyDown(paramInt, paramKeyEvent);
        }
      });
      return bool;
    case 24:
    case 25:
      return super.onKeyDown(paramInt, paramKeyEvent);
    }
    return false;
  }

  public boolean onKeyUp(int paramInt, KeyEvent paramKeyEvent)
  {
    return onKeyDown(paramInt, paramKeyEvent);
  }

  public void onPause()
  {
    queueEvent(new Runnable()
    {
      public void run()
      {
        EngineGLSurfaceView.this.mCocos2dxRenderer.handleOnPause();
      }
    });
    super.onPause();
  }

  public void onResume()
  {
    super.onResume();
    queueEvent(new Runnable()
    {
      public void run()
      {
        EngineGLSurfaceView.this.mCocos2dxRenderer.handleOnResume();
      }
    });
  }

  protected void onSizeChanged(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    if (!isInEditMode())
      this.mCocos2dxRenderer.setScreenWidthAndHeight(paramInt1, paramInt2);
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    if (!isEnabled())
      return false;
    int i = paramMotionEvent.getPointerCount();
    final int[] arrayOfInt = new int[i];
    final float[] arrayOfFloat1 = new float[i];
    final float[] arrayOfFloat2 = new float[i];
    for (int j = 0; j < i; j++)
    {
      arrayOfInt[j] = paramMotionEvent.getPointerId(j);
      arrayOfFloat1[j] = paramMotionEvent.getX(j);
      arrayOfFloat2[j] = paramMotionEvent.getY(j);
    }
    switch (0xFF & paramMotionEvent.getAction())
    {
    case 4:
    default:
    case 5:
    case 0:
    case 2:
    case 6:
    case 1:
    case 3:
    }
    while (true)
    {
      return true;
      int i2 = paramMotionEvent.getAction() >> 8;
      final int i3 = paramMotionEvent.getPointerId(i2);
      final float f7 = paramMotionEvent.getX(i2);
      final float f8 = paramMotionEvent.getY(i2);
      Runnable local5 = new Runnable()
      {
        public void run()
        {
          EngineGLSurfaceView.this.mCocos2dxRenderer.handleActionDown(i3, f7, f8);
        }
      };
      queueEvent(local5);
      continue;
      final int i1 = paramMotionEvent.getPointerId(0);
      final float f5 = arrayOfFloat1[0];
      final float f6 = arrayOfFloat2[0];
      Runnable local6 = new Runnable()
      {
        public void run()
        {
          EngineGLSurfaceView.this.mCocos2dxRenderer.handleActionDown(i1, f5, f6);
        }
      };
      queueEvent(local6);
      continue;
      Runnable local7 = new Runnable()
      {
        public void run()
        {
          EngineGLSurfaceView.this.mCocos2dxRenderer.handleActionMove(arrayOfInt, arrayOfFloat1, arrayOfFloat2);
        }
      };
      queueEvent(local7);
      continue;
      int m = paramMotionEvent.getAction() >> 8;
      final int n = paramMotionEvent.getPointerId(m);
      final float f3 = paramMotionEvent.getX(m);
      final float f4 = paramMotionEvent.getY(m);
      Runnable local8 = new Runnable()
      {
        public void run()
        {
          EngineGLSurfaceView.this.mCocos2dxRenderer.handleActionUp(n, f3, f4);
        }
      };
      queueEvent(local8);
      continue;
      final int k = paramMotionEvent.getPointerId(0);
      final float f1 = arrayOfFloat1[0];
      final float f2 = arrayOfFloat2[0];
      Runnable local9 = new Runnable()
      {
        public void run()
        {
          EngineGLSurfaceView.this.mCocos2dxRenderer.handleActionUp(k, f1, f2);
        }
      };
      queueEvent(local9);
      continue;
      Runnable local10 = new Runnable()
      {
        public void run()
        {
          EngineGLSurfaceView.this.mCocos2dxRenderer.handleActionCancel(arrayOfInt, arrayOfFloat1, arrayOfFloat2);
        }
      };
      queueEvent(local10);
    }
  }

  public void setCocos2dxEditText(EngineEditText paramEngineEditText)
  {
    this.mCocos2dxEditText = paramEngineEditText;
    if ((this.mCocos2dxEditText != null) && (sCocos2dxTextInputWraper != null))
    {
      this.mCocos2dxEditText.setOnEditorActionListener(sCocos2dxTextInputWraper);
      this.mCocos2dxEditText.setCocos2dxGLSurfaceView(this);
      requestFocus();
    }
  }

  public void setEngineRenderer(Renderer paramRenderer)
  {
    this.mCocos2dxRenderer = paramRenderer;
    setRenderer(this.mCocos2dxRenderer);
  }

  public void setRotation(int paramInt)
  {
    this.mCocos2dxRenderer.setRotation(paramInt);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.melesta.engine.EngineGLSurfaceView
 * JD-Core Version:    0.6.2
 */